package zhtt01.main;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import zhtt01.dao.OrganizationDao;
import zhtt01.dao.UserDao;
import zhtt01.service.OrganizationService;
import zhtt01.service.UserService;

public class Main {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("zhtt01.config");
        /**
         * UserServce可以调用成功，
         * 因为 在ApplicationConfig中有 @Import({UserService.class,OrganizationService.class})
         */
        UserService userService = context.getBean(UserService.class);
        userService.save();
        /**
         * OrganizationService可以调用成功，
         * 因为 在ApplicationConfig中有 @Import({UserService.class,OrganizationService.class})
         */
        OrganizationService organizationService = context.getBean(OrganizationService.class);
        organizationService.save();
        /**
         * organizationDao可以调用成功，
         * 因为 在ApplicationConfig中有 @ComponentScan(basePackages = { "zhtt01.dao" }) 同时在OrganizationDao中有@Service
         */
        OrganizationDao organizationDao = context.getBean(OrganizationDao.class);
        organizationDao.save();
        /**
         * userDao调用失败，
         * 因为 在ApplicationConfig中有 @ComponentScan(basePackages = { "zhtt01.dao" }) UserDao中无@Service
        UserDao userDao = context.getBean(UserDao.class);
        userDao.save();
         */
    }
}